local laohuoshou = fk.CreateSkill {

  name = "joy__huoshou",

  tags = { Skill.Compulsory, },

}



laohuoshou:addEffect(fk.PreCardEffect, {
  name = "joy__huoshou",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(laohuoshou.name) and data.card.trueName == "savage_assault" then
      if event == fk.PreCardEffect then
        return player.id == data.to
      else
        return target ~= player and data.firstTarget
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      return true
    else
      data.extra_data = data.extra_data or {}
      data.extra_data.huoshou = player.id
      if not player.dead then
        player:drawCards(1,laohuoshou.name)
      end
    end
  end,
})
laohuoshou:addEffect(fk.TargetSpecified, {
  name = "joy__huoshou",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(laohuoshou.name) and data.card.trueName == "savage_assault" then
      if event == fk.PreCardEffect then
        return player.id == data.to
      else
        return target ~= player and data.firstTarget
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      return true
    else
      data.extra_data = data.extra_data or {}
      data.extra_data.huoshou = player.id
      if not player.dead then
        player:drawCards(1,laohuoshou.name)
      end
    end
  end,
})
laohuoshou:addEffect(fk.PreDamage, {
  refresh_events = {fk.PreDamage},
  can_refresh = function(self, event, target, player, data)
    if data.card and data.card.trueName == "savage_assault" then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if e then
        local use = e.data[1]
        return use.extra_data and use.extra_data.huoshou
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e then
      local use = e.data[1]
      data.from = room:getPlayerById(use.extra_data.huoshou)
    end
  end,
})

return laohuoshou